const fs = require('fs');
const path = require('path');
module.exports = () => {
    return async (ctx,next) => {
        let startTime = new Date().getTime();   //开始的时间戳
        await next();
        let endTime = new Date().getTime();     //结束的时间戳
        let time = endTime - startTime;         //本次请求花费的时间
        // 路径-请求方式-请求状态-耗时
        // ctx.path  ctx.method  ctx.status 
        fs.appendFileSync(path.join(process.cwd(),'log.log'),`${ctx.path}-${ctx.method}-${ctx.status}-${time}\n`)
    }
}